package com.nikitova.craps3d.view.components 
{
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.Event;
	import flash.text.TextField;
	import flash.text.TextFieldType;	

	/**
	 * @author schranz
	 */
	public class GameDataPreloader extends Sprite
	{
		private var _percentsLoaded:TextField;

		public function GameDataPreloader() 
		{			
			addEventListener(Event.ADDED_TO_STAGE, addedToStage, false, 0, true);
		}

		private function addedToStage(event : Event) : void
		{
			removeEventListener(Event.ADDED_TO_STAGE, addedToStage);

			_percentsLoaded = new TextField();
			_percentsLoaded.textColor = 0xFFFFFF;
			_percentsLoaded.border = true;
			_percentsLoaded.background = false;
			_percentsLoaded.type = TextFieldType.DYNAMIC;
			_percentsLoaded.borderColor = 0x000000;
			_percentsLoaded.width = 150;
			_percentsLoaded.height = 20;	
			_percentsLoaded.x = (stage.stageWidth - _percentsLoaded.width) / 2;
			_percentsLoaded.y = stage.stageHeight / 2;				
			_percentsLoaded.text = "";			
			addChild(_percentsLoaded);
		}

		public function updatePercents(percents : Number) : void
		{
			_percentsLoaded.text = "Loading..   " + percents + " %";
		}

		public function hideShowUI(value : Boolean) : void
		{
			_percentsLoaded.visible = value;
		}        

	}
}